package com.hrzyit.whistle.im.ui.adapter.holder

import android.os.Handler
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.hrzyit.base.utils.IMUtils
import com.hrzyit.whistle.im.R
import com.hrzyit.whistle.im.entity.MessageInfo
import com.hrzyit.whistle.im.ui.adapter.ChatAdapter
import com.jude.easyrecyclerview.adapter.BaseViewHolder
import kotlinx.android.synthetic.main.item_chat_accept.view.*

class ChatAcceptViewHolder(
    parent: ViewGroup,
    private val onItemClickListener: ChatAdapter.OnItemClickListener,
    private val handler: Handler
) : BaseViewHolder<MessageInfo>(parent, R.layout.item_chat_accept) {

    //    @Bind(R.id.chat_item_date)
//    internal var chatItemDate: TextView? = null
//    @Bind(R.id.chat_item_header)
//    internal var chatItemHeader: ImageView? = null
//    @Bind(R.id.chat_item_content_text)
//    internal var chatItemContentText: GifTextView? = null
//    @Bind(R.id.chat_item_content_image)
//    internal var chatItemContentImage: BubbleImageView? = null
//    @Bind(R.id.chat_item_voice)
//    internal var chatItemVoice: ImageView? = null
//    @Bind(R.id.chat_item_layout_content)
//    internal var chatItemLayoutContent: LinearLayout? = null
//    @Bind(R.id.chat_item_voice_time)
//    internal var chatItemVoiceTime: TextView? = null
    override fun setData(data: MessageInfo?) {
        itemView.mChatItemDateTv!!.text = if (data!!.time != null) data.time else ""
        // 加载图片
        Glide.with(context).load(data.header).into(itemView.mChatItemHeaderIv)
        itemView.mChatItemHeaderIv!!.setOnClickListener { onItemClickListener.onHeaderClick(dataPosition) }
        when {
            data.content != null -> {
                itemView.mChatItemContentText!!.setSpanText(handler, data.content, true)
                itemView.mChatItemVoiceIv!!.visibility = View.GONE
                itemView.mChatItemContentText!!.visibility = View.VISIBLE

                itemView.mChatItemLayoutContentLl!!.visibility = View.VISIBLE
                itemView.mChatItemVoiceTimeTv!!.visibility = View.GONE
//                itemView.mChatItemContentImage!!.visibility = View.GONE
            }
            data.imageUrl != null -> {
                itemView.mChatItemVoiceIv!!.visibility = View.GONE
                itemView.mChatItemLayoutContentLl!!.visibility = View.GONE
                itemView.mChatItemVoiceTimeTv!!.visibility = View.GONE
                itemView.mChatItemContentText!!.visibility = View.GONE
//                itemView.mChatItemContentImage!!.visibility = View.VISIBLE
//                Glide.with(context).load(data.imageUrl).into(itemView.mChatItemContentImage)
//                itemView.mChatItemContentImage!!.setOnClickListener {
//                    onItemClickListener.onImageClick(
//                        itemView.mChatItemContentImage,
//                        dataPosition
//                    )
//                }
            }
            data.filepath != null -> {
                itemView.mChatItemVoiceIv!!.visibility = View.VISIBLE
                itemView.mChatItemLayoutContentLl!!.visibility = View.VISIBLE
                itemView.mChatItemContentText!!.visibility = View.GONE
                itemView.mChatItemVoiceTimeTv!!.visibility = View.VISIBLE
//                itemView.mChatItemContentImage!!.visibility = View.GONE
                itemView.mChatItemVoiceTimeTv!!.text = IMUtils.formatTime(data.voiceTime)
                itemView.mChatItemLayoutContentLl!!.setOnClickListener {
                    onItemClickListener.onVoiceClick(
                        itemView.mChatItemVoiceIv,
                        dataPosition
                    )
                }
            }
        }
    }
}
